package com.dries.portal.module.coupon.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * @Description: 分发目标
 * @Author ZSY
 * @createTime 2020/7/27 10:27
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
public enum DistributeTarget {

    SINGLE(1, "单用户"),
    MULTI(2, "多用户");

    /**
     * 分发目标编码
     */
    @EnumValue
    private Integer code;
    /**
     * 描述
     */
    private String desc;

    @JsonValue
    public String getDesc() {
        return desc;
    }

    public static DistributeTarget of(Integer code) {
        Objects.requireNonNull(code);

        return Stream.of(values()).filter(e -> e.getCode().equals(code))
                .findAny()
                .orElseThrow(() -> new IllegalArgumentException(code + "not exists!"));
    }

}
